

class Solution:
    def removeNthFromEnd(self, head, n):
        
        # 先后指针
        # 需要考虑第一个节点被移除的情况
        dummy = ListNode(0)
        dummy.next = head
        prx = dummy
        cur = dummy

        for _ in range(n):
            prx = prx.next
        # flag = False
        while prx and prx.next:
            prx = prx.next
            cur = cur.next
            # flag = True
        # if not flag:
        #     dummy.next = dummy.next.next
        # else:
        cur.next = cur.next.next

        return dummy.next
    
        

